//
//  YKMineResultViewController.m
//  YunKang
//
//  Created by leoking870 on 2017/10/4.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKMineResultViewController.h"
#import "YKPerformanceListViewController.h"
#import "YKRequestExchangeViewController.h"
@interface YKMineResultViewController ()
@property (nonatomic, strong)UILabel *performanceScoreLabel;
@end

@implementation YKMineResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我的业绩";
    self.view.backgroundColor = [UIColor whiteColor];
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"myPerformance_header_bg"]];
    [self.view addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.equalTo(self.view);
    }];
    
    UILabel *performanceScoreLabel = [[UILabel alloc]init];
    performanceScoreLabel.text = @"18888.88";
    performanceScoreLabel.font = [UIFont boldSystemFontOfSize:45];
    performanceScoreLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:performanceScoreLabel];
    [performanceScoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(imageView);
    }];
    self.performanceScoreLabel = performanceScoreLabel;
    UIButton *performanceDetailButton = [[UIButton alloc]init];
    [performanceDetailButton setTitle:@"业绩明细" forState:UIControlStateNormal];
    [performanceDetailButton setImage:[UIImage imageNamed:@"myPerformance_tab_icon_1"] forState:UIControlStateNormal];
    [performanceDetailButton setTitleColor:[UIColor tf_colorWithHexString:@"#f1f1f1"] forState:UIControlStateNormal];
    performanceDetailButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [performanceDetailButton setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
    [performanceDetailButton addTarget:self action:@selector(performanceDetail:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *requestExchangeButton = [[UIButton alloc]init];
    [requestExchangeButton setTitle:@"申请兑换" forState:UIControlStateNormal];
    [requestExchangeButton setImage:[UIImage imageNamed:@"myPerformance_tab_icon_2"] forState:UIControlStateNormal];
    [requestExchangeButton setTitleColor:[UIColor tf_colorWithHexString:@"#f1f1f1"] forState:UIControlStateNormal];
    requestExchangeButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [requestExchangeButton setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
    [requestExchangeButton addTarget:self action:@selector(requestExchange:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:performanceDetailButton];
    [self.view addSubview:requestExchangeButton];
    
    [@[performanceDetailButton, requestExchangeButton] mas_alignAlongAxis:MASAxisTypeHorizontal spaceType:MASAlignChildrenSpaceAround];
    
    [@[performanceDetailButton, requestExchangeButton] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).offset(15);
    }];
    
    UIView *bottomLine = [UIView new];
    bottomLine.backgroundColor = [UIColor tf_colorWithHexString:@"#d3d4d4"];
    [self.view addSubview:bottomLine];
    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.view);
        make.top.equalTo(performanceDetailButton.mas_bottom).offset(15);
        make.height.mas_equalTo(.5f);
    }];
    
    UIView *middleLine = [UIView new];
    middleLine.backgroundColor = [UIColor tf_colorWithHexString:@"#d3d4d4"];
    [self.view addSubview:middleLine];
    [middleLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(imageView.mas_bottom).offset(5);
        make.bottom.equalTo(bottomLine.mas_top).offset(-5);
        make.width.mas_equalTo(.5f);
    }];
    [self loadData];
}

- (void)loadData {
    [self tf_showStateView:kTFViewStateLoading];
    [TFHTTPMANAER POST:@"personalCentr/searchAchievementIntegral.htm" parameters:@{} success:^(id responseObject) {
        NSInteger achievementIntegral = [responseObject[@"achievementIntegral"]integerValue];
        self.performanceScoreLabel.text = [NSString stringWithFormat:@"%zd", achievementIntegral];
        [self tf_showStateView:kTFViewStateNone];
    } failure:^(id responseObject, NSError *error) {
        [self tf_showStateView:kTFViewStateNetError];
    }];
}

- (void)performanceDetail:(id)sender {
    YKPerformanceListViewController *vc = [[YKPerformanceListViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)requestExchange:(id)sender {
    YKRequestExchangeViewController *vc = [[YKRequestExchangeViewController alloc]init];
//    vc.leftScore = self.performanceScoreLabel.text;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
